package workai.fcx.com.message_module.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hxh.component.basicore.Base.adapter.BaseRecyAdapter;
import com.hxh.component.basicore.Base.onRecyItemLongClick;
import com.hxh.component.basicore.util.Utils;

import workai.fcx.com.message_module.R;
import workai.fcx.com.message_module.bean.MyMsgDTO;


public class MyMsgAdapter extends BaseRecyAdapter<MyMsgDTO, MyMsgAdapter.VH> {
    public MyMsgAdapter(Context context) {
        super(context);
    }

    public MyMsgAdapter(Context context, onRecyItemLongClick<MyMsgDTO,VH> itemLongClick ) {
        super(context);
        setmItemLongClickCallBack(itemLongClick);
    }

    @Override
    public VH newViewHolder(View view) {
        return new VH(view);
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_mymsg;
    }

    @Override
    public void onBindViewHolder(final VH holder, final int position) {
        final MyMsgDTO item = getmDatas().get(position);
        holder.tv_name.setText(item.getSubject());
        holder.tv_msg.setText(item.getContent());
        String end_time = Utils.Time.getDateForFormate(item.getCreated_at()*1000L, Utils.Time.YYYYMMDDHHMM);
        holder.tv_time.setText(end_time);
        loadimg(holder.iv_img,R.mipmap.ic_message);
        holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                getmItemLongClickCallBack().onLongClick(position,ITEMMAINVIEW,item,holder);
                return false;
            }
        });
    }

    public class VH extends RecyclerView.ViewHolder {
        private TextView tv_time;
        private TextView tv_name;
        private TextView tv_msg;
        private ImageView iv_img;
        public VH(View itemView) {
            super(itemView);
            iv_img = (ImageView) itemView.findViewById(R.id.iv_img);
            tv_time = (TextView) itemView.findViewById(R.id.tv_time);
            tv_name = (TextView) itemView.findViewById(R.id.tv_name);
            tv_msg = (TextView) itemView.findViewById(R.id.tv_msg);
        }
    }
}